package com.yayo.mangement.model;

import com.yayo.mangement.conf.DbConfig;
import com.yayo.mangement.authentication.enums.PropertyTypeEnum;
import com.yayo.mangement.utils.StringUtils;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class TableField {

    /**主键标识*/
    private boolean keyIdentityFlag;
    /**
     * 字段名
     */
    private String columnName;
    /**
     * 字段类型
     */
    private String columnType;
    /**
     *  类属性名称
     */
    private String propertyName;
    /**
     * 对应类属性类型枚举
     */
    private PropertyTypeEnum propertyTypeEnum;
    /**
     * 字段注释
     */
    private String comment;

    /**
     * 属性类型
     */
    private String propertyType;
    /**
     * 属性包名
     */
    private String packageName;

    public void setColumnType(String columnType){
        this.columnType = columnType;
        this.setPropertyTypeEnum(DbConfig.columnConverter.processConverter(columnType));
    }

    public void setColumnName(String columnName){
        this.columnName = columnName;
        this.propertyName = StringUtils.getNoUnderlineStr(columnName);
    }

    public void setPropertyTypeEnum(PropertyTypeEnum propertyTypeEnum){
        this.propertyTypeEnum = propertyTypeEnum;
        this.propertyType = propertyTypeEnum.getType();
        this.packageName = propertyTypeEnum.getPkg();
    }

}
